//
//  XKPresentationController.swift
//  WeiboSwift
//
//  Created by xiaokui wu on 9/10/16.
//  Copyright © 2016 wxk. All rights reserved.
//

import UIKit

class XKPresentationController: UIPresentationController {
    
    var presentedViewFrame = CGRectZero

    override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
    }
    
    override func containerViewWillLayoutSubviews() {

        //containerView // The view in which a presentation occurs. It is an ancestor of both the presenting and presented view controller's views.
        // 弹出的view
        presentedView()?.frame = presentedViewFrame
        presentedView()?.center.x = (containerView?.center.x)!
        
        containerView?.insertSubview(coverBtn, atIndex: 0)
        coverBtn.addTarget(self, action: #selector(coverBtnClick), forControlEvents: .TouchUpInside)
    }
    
    // MARK: - lazy
    private lazy var coverBtn: UIButton = {
        let btn = UIButton()
        btn.frame = UIScreen.mainScreen().bounds
        
        return btn
    }()
    
    // MARK: - event
    @objc private func coverBtnClick()
    {
        Log("")
        presentingViewController.dismissViewControllerAnimated(true, completion: nil)
    }
}
